from math import exp

from cloudVirtrualizedNetworkApplicationReliability.src.applicationAvailabilityCalculation import *


def availability_time_t(t, lam, miu):
    rt = (lam * miu + miu ** 2) / (lam ** 2 + lam * miu + miu ** 2)
    s1 = - (lam + miu) + (lam * miu) ** 0.5
    s2 = - (lam + miu) - (lam * miu) ** 0.5
    rtt = rt - (lam ** 2 * (s2 * exp(s1 * t) - s1 * exp(s2 * t))) / (s1 * s2 * (s1 - s2))
    return rtt


if __name__ == '__main__':
    file = "case_4server_2link_backup_ms.xlsx"
    network = CloudVirtualizedNetwork(file, control_plane_type=ControlPlaneType.NONE)
    l = 1 / time_format(network.fail_info.loc[0, "MTBF"])
    u = 1 / time_format(network.fail_info.loc[0, "MTTR"])
    result = pd.DataFrame()
    for t in [50, 100, 200]:
        r1 = multi_process_avail_cal(file, t, 100, 50, ControlPlaneType.NONE, "result.xlsx")
        result_s = r1.iloc[0].to_list()
        result_t = availability_time_t(t, l, u)
        result_s.append(result_t)
        result[t] = result_s
    result.to_csv("ms.csv")
